﻿namespace KeRui.DAL
{
    using KeRui.DBUtility;
    using KeRui.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CmsCatchParseRegex
    {
        public int Add(KeRui.Model.CmsCatchParseRegex model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ParseID", SqlDbType.Int, 4), new SqlParameter("@FieldName", SqlDbType.VarChar, 50), new SqlParameter("@Pattern", SqlDbType.NVarChar), new SqlParameter("@Replacement", SqlDbType.NVarChar) };
            parameters[0].Value = model.ParseID;
            parameters[1].Value = model.FieldName;
            parameters[2].Value = model.Pattern;
            parameters[3].Value = model.Replacement;
            return DbHelperSQL.RunProcedure("CmsCatchParseRegex_ADD", parameters, out num);
        }

        public void Delete(int ID)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            DbHelperSQL.RunProcedure("CmsCatchParseRegex_Delete", parameters, out num);
        }

        public KeRui.Model.CmsCatchParseRegex GetModel(int ID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) };
            parameters[0].Value = ID;
            KeRui.Model.CmsCatchParseRegex regex = new KeRui.Model.CmsCatchParseRegex();
            DataSet set = DbHelperSQL.RunProcedure("CmsCatchParseRegex_GetModel", parameters, "ds");
            if (set.Tables[0].Rows.Count > 0)
            {
                if (set.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    regex.ID = int.Parse(set.Tables[0].Rows[0]["ID"].ToString());
                }
                if (set.Tables[0].Rows[0]["ParseID"].ToString() != "")
                {
                    regex.ParseID = int.Parse(set.Tables[0].Rows[0]["ParseID"].ToString());
                }
                regex.FieldName = set.Tables[0].Rows[0]["FieldName"].ToString();
                regex.Pattern = set.Tables[0].Rows[0]["Pattern"].ToString();
                regex.Replacement = set.Tables[0].Rows[0]["Replacement"].ToString();
                if (set.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    regex.CreateTime = DateTime.Parse(set.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                return regex;
            }
            return null;
        }

        public void Update(KeRui.Model.CmsCatchParseRegex model)
        {
            int num;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@FieldName", SqlDbType.VarChar, 50), new SqlParameter("@Pattern", SqlDbType.NVarChar), new SqlParameter("@Replacement", SqlDbType.NVarChar) };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.FieldName;
            parameters[2].Value = model.Pattern;
            parameters[3].Value = model.Replacement;
            DbHelperSQL.RunProcedure("CmsCatchParseRegex_Update", parameters, out num);
        }
    }
}

